package com.bdweb.mokuai;/*
package mqtt.impl;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

import java.nio.charset.Charset;

public class MQTT extends Thread{
    public MQTT() {
        String topic = "test2";
        int qos = 1;
        String broker = "tcp://127.0.0.1";
        String userName = "456";
        String password = "456";
        String clientId = "emqx_ODg1Nz";
        // 内存存储
        MemoryPersistence persistence = new MemoryPersistence();
        MqttClient sampleClient = null;
        try {
            // 创建客户端
            sampleClient = new MqttClient(broker, clientId, persistence);
            // 创建链接参数
            MqttConnectOptions connOpts = new MqttConnectOptions();
            // 在重新启动和重新连接时记住状态
            connOpts.setCleanSession(false);
            // 设置连接的用户名
            connOpts.setUserName(userName);
            connOpts.setPassword(password.toCharArray());
            // // 设置连接超时
            connOpts.setConnectionTimeout(30);


            // 建立连接
            System.out.println("连接到 broker: " + broker);
            sampleClient.connect(connOpts);
            System.out.println("连接成功.");

            int i = 1;

            String s = "00";
            // 创建消息
            MqttMessage mmg = new MqttMessage(s.getBytes(Charset.defaultCharset()));
            // 设置消息的服务质量
            mmg.setQos(qos);
            // 发布消息
            System.out.println("向" + topic + "发送消息:" + s);
            sampleClient.publish(topic, mmg);
            Thread.sleep(3000);

//
        } catch (MqttException me) {
            System.out.println("reason " + me.getReasonCode());
            System.out.println("msg " + me.getMessage());
            System.out.println("loc " + me.getLocalizedMessage());
            System.out.println("cause " + me.getCause());
            System.out.println("excep " + me);
            me.printStackTrace();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        // 断开连接
        //sampleClient.disconnect();
//            // 关闭客户端
          // sampleClient.close();
    }


}
*/
